<template>
  <section class="welfare-account-main">
    <!-- <section class="main-search merge">
      <span class="svg-container">
        <svg-icon icon-class="search" />
      </span>
      <el-input v-model.trim="listQuery.subAcntNm" placeholder="输入子账户名称搜索" class="search-input" @keyup.enter.native="handleFilter" />
      <section class="search-btn">
        <el-button class="filter-item" type="primary" @click="handleFilter">搜索</el-button>
        <el-button type="primary" @click="handleReset">重置</el-button>
      </section>
    </section>-->

    <section class="main-buttons">
      <section class="main-buttons-title">
        <span>职工福利子账户管理</span>
        <!-- <span>
          (
          最多可以有
          <span class="num">14</span>个子账号)
        </span> -->
      </section>
      <section class="main-buttons-btns">
        <el-button style="margin-left: 10px" @click="handleCreate">新建</el-button>
      </section>
    </section>

    <section class="main-table">
      <v-table :list="list" tag="accountmain" :list-loading="listLoading" :cell-style="cellStyle" :filter-column="filtercolumn">
        <el-table-column label="操作" fixed="right" align="center" min-width="100" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
						 <el-button v-if="scope.row.balance!='0'" type="text" size="mini" @click="handleStatistics(scope.row)">余额统计</el-button>
          </template>
        </el-table-column>
      </v-table>
      <!-- <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" /> -->
    </section>
  </section>
</template>
<script>
import { queryPage } from './../api'
// import Pagination from '@/components/Pagination'
import VTable from '@/components/Table'
export default {
  name: 'WelfareAccount',
  components: { VTable },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
        subAcntNm: ''
      },
      list: [],
      total: 0,
      listLoading: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
		cellStyle(scope,item){
			
		},
    filtercolumn(scope, item) {
      if (item === 'subAcntSt') {
        return (scope.row[item] === 0 || scope.row[item] === '0') ? '可用' : '不可用'
      } else if (item === 'subAcntStartTm' || item === 'subAcntEndTm') {
        if (scope.row[item]) {
          return scope.row[item].replace(/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/, '$1-$2-$3 $4:$5:$6')
        } else {
          return ''
        }
      }else if(item=='balance'){
				return scope.row[item]? `<p style="text-align:right;">${scope.row[item]}</p>`:''
			} else {
        return scope.row[item]
      }
    },

    handleReset() {
      // this.listQuery.page = 1
      this.listQuery.subAcntNm = ''
      this.getList()
    },

    handleFilter() {
      // this.listQuery.page = 1
      this.getList()
    },

    handleCreate() {
      this.$router.push({path:this.$filterPath("manage") , query: { t: 'c' } })
    },

    handleUpdate(row) {
      this.$router.push({path:this.$filterPath("manage") , query: { t: 'u', i: row.subAcntTp } })
    },
		handleStatistics(row){
			this.$router.push({path:this.$filterPath("statistics") , query: {i: row.subAcntTp } })
		},

    getList(obj) {
      this.listLoading = true
      return new Promise((resolve, reject) => {
        queryPage({}).then(response => {
          this.list = response.data.data || []
          // this.total = response.data.data.total
          this.listLoading = false
        }).catch(error => {
          reject(error)
          this.listLoading = false
        })
      })
    }
  }
}
</script>
<style lang="scss">
@import '@/styles/mixin.scss';
.welfare-account-main {
  padding: 10px;
  .main-search {
    background-color: #fff;
    padding: 0 10px;
    .svg-container {
      padding: 0 5px 0 10px;
      color: #bfced6;
      vertical-align: middle;
      display: inline-block;
    }
    .search-input {
      width: 60%;
      position: relative;
      &:after {
        content: '';
        position: absolute;
        left: -25px;
        right: 0;
        bottom: 8px;
        height: 1px;
        background: rgba(226, 227, 232, 1);
      }
      input {
        outline: none;
        background: transparent;
        border: none;
        outline: medium;
        padding: 0;
        &:focus {
          outline: none;
          background-color: transparent;
        }
      }
    }
    .search-btn {
      display: inline-block;
      float: right;
      .el-button.is-round {
        padding: 10px 30px;
        margin-right: 34px;
      }
      .search-more {
        font-size: 14px;
        font-weight: 500;
        @include font-color($mainColor);
        cursor: pointer;
        margin-left: 10px;
      }
    }

    &.merge {
      height: 50px;
      line-height: 50px;
    }
  }

  .main-buttons {
    display: flex;
    line-height: 36px;
    margin-bottom: 10px;
    .main-buttons-title {
      flex: 1;
      height: 36px;
      line-height: 36px;
      font-size: 16px;
      font-weight: bold;
      color: rgba(51, 51, 51, 1);
      .num {
        @include font-color($mainColor);
      }
    }
  }
}
</style>
